
<script language="javascript">
	function kiemtra()
	{
		if (document.form1.TuKhoa.value=="")
		{
			alert("Nhập từ khóa cần tìm");
			document.form1.TuKhoa.focus();
			return;
		}
		document.form1.submit();
	}
</script>
<?php 
	include_once('includes/class_pages.php');	
	include_once ('class_sanpham.php');
error_reporting(E_ALL^E_NOTICE);
?>
<!--		BẮT ĐẦU PHÂN CHINH GIUA CUA TRANG-->

<form id="form1" name="form1" method="post" action="index.php?com=SanPham&fun=timkiemcoban"><label></label><label></label>
  <p><label></label>
    <label></label>
    <label></label>
    <label></label></p>
  <table width="800" height="0" border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>
      <td width="111" height="67"><p><strong>Từ khóa tìm kiếm </strong></p>
        <label></label>
        <label> </label>
      <p>&nbsp;</p></td>
      <td width="382"><label></label>
        <label></label> 
        <p>
          <label>
            <input name="TuKhoa" type="text" id="TuKhoa" value="<?php echo $_POST['TuKhoa']?>" size="40">
            <input name="timkiem" type="submit" id="timkiem" value="Tìm kiếm" onClick="kiemtra()">
            <br />
            <br />
            <input type="radio" name="chon" value="HangSX" />
            <strong>            Hãng sản xuất </strong></label>
          <strong>
          <label>
            <input type="radio" name="chon" value="tags" />
            Chức năng</label>
          <label>
              <input name="chon" type="radio" value="TenSanPham" checked="checked"/>
            Tên sản phẩm </label>
          </strong></td>
		</p>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<?php
	$connection = mysql_connect("localhost","root","");
	if(!$connection)
	{
		die('Not connected: '.mysql_error());
	}
	$isSuccess = mysql_select_db("ntson01_nhom04",$connection);
	if(!$isSuccess)
	{
		die('Can not selected database: '.mysql_error());
	}
	$eb = new class_sanpham();
	if(isset($_POST["TuKhoa"]))
	{
		$tukhoa = $_POST["TuKhoa"];
		$pager = new Pager();
		$chon = $_POST["chon"];
		$sql_1 = "select sp.*,nb.HoTen  from san_pham sp, nguoi_ban nb where sp.MaNguoiban = nb.MaSo and NhaSanXuat like '%$tukhoa%' and TinhTrangDang=1";
		$sql_2 = "select sp.*,nb.HoTen  from san_pham sp, nguoi_ban nb where sp.MaNguoiban = nb.MaSo and Mota like '%$tukhoa%' and TinhTrangDang=1";
		$sql_3 = "select sp.*,nb.HoTen  from san_pham sp, nguoi_ban nb where sp.MaNguoiban = nb.MaSo and TenSanPham like '%$tukhoa%' and TinhTrangDang=1";
		if($chon == "HangSX")
		{
			$result = mysql_query($sql_1);
			$tb = $eb->TimKiem($sql_1);
		}
		if($chon == "tags")
		{
			$result = mysql_query($sql_2);
			$tb = $eb->TimKiem($sql_2);
		}
		if($chon == "TenSanPham")
		{
			$result = mysql_query($sql_3);
			$tb = $eb->TimKiem($sql_3);
		}
	}
		
		$str = '';
		if (count($tb) == 0)
		{
			echo '<br/><div align="center"><b>Không có sản phẩm nào.</b></div>';
		}else{
				$str .= '<h1>Kết Quả tìm kiếm</h1>';
					foreach ($tb as $row)
					{
					$str .= '<table align="center" width="710" border="0">
			  <tr>
			    <td width="130" rowspan="6"><img src="images/sanpham/'.$row['HinhAnh'].'" width="120px" height="160px" /></td>
			    <td align="left" colspan="2" style="font-weight:bold; font-size:16px">';
				
				if ($row['TenSanPham'] == NULL)
				{
					$row['TenSanPham'] = 'sản phẩm bị xóa';
				}
				
				$str .= '<a href="index.php?com=sanpham&fun=detail&MaSanPham='.$row['MaSo'].'">'.$row['TenSanPham'].'</a></td>
			  </tr>
			  <tr>
			    <td width="290">Danh mục: '.$row['TenDanhMuc'].'</td>
				<td>Người bán: '.$row['HoTen'].'</td>
			  </tr>
			  <tr>
			    <td>Giá bán: '.$row['GiaSanPham'].' VND</td>
				<td>Số lượng: '.$row['SoLuong'].' '.$row['TenDonViTinh'].' </td>
			  </tr>
			  <tr>
			    <td>Nhà sản xuất: '.$row['NhaSanXuat'].'</td>
				<td>Điểm: '.$row['DiemDanhGia'].'</td>
			  </tr>
			  <tr>';
			  
				$ThoiGian = $row['NgayDang'];
				$nam = substr($ThoiGian,0,4);
				$thang = substr($ThoiGian,5,2);
				$ngay = substr($ThoiGian,8,2);
				$gio = substr($ThoiGian,11,2);
				$phut = substr($ThoiGian,14,2);
				$giay = substr($ThoiGian,17,2);
				$ThoiGian = $gio.':'.$phut.':'.$giay.' '.$ngay.'/'.$thang.'/'.$nam;
			  
			    $str .= '<td>Ngày đăng: '.$ThoiGian.'</td>
				<td>Lượt xem: '.$row['PageView'].'</td>
			  </tr>';
			  
			  if($row['HaveTag'] == 1)
			  {
				  $dm = new class_danhmuc();
				  $str .= '<tr>
			    				<td colspan="2">Tag:';
				  $tbTag = $dm->ListTagByMaSanPham($row['MaSo']);
				  foreach ($tbTag as $rowTag)
				  {
					  $str .= ' <a href="index.php?com=tag&fun=detail&MaTag='.$rowTag['MaSo'].'&TenTag='.$rowTag['TenTag'].'">'.$rowTag['TenTag'].'</a>';
				  }
				  $str .= '</td>
			  				</tr>';
			  }
			  else
			  {
				  $str .= '<tr>
			    			<td colspan="2"></td>
			  			</tr>';
			  }
			  
			  
			  $str .= '<tr>
			    <td colspan="3">
			    <hr align="center" style="border:thin dotted" color="#00CC00"  />
			    </td>
			 </tr>
			</table>';
					
				}
				echo $str;
		}
		
	
	
?>

<!--		KÊT THÚC PHÂN CHINH GIUA CUA TRANG-->
